package com.gz.service;

import com.gz.dao.DiningTableDao;
import com.gz.domain.DiningTable;

import java.util.ArrayList;
import java.util.List;

public class DiningTableService {
    //定义一个DiningTableDao对象
    private DiningTableDao diningTableDao=new DiningTableDao();

    //返回所有餐桌信息
   public List<DiningTable> list(){
       return diningTableDao.queryMulti("select id,state from diningtable",DiningTable.class);
   }

   //如果返回null，表示id编号对应的餐桌不存在
    public DiningTable getDiningTableById(int id){
        return diningTableDao.querySingle("select * from diningtable where id = ?",DiningTable.class,id);
    }

    //如果餐桌可以预定，调用方法，对其状态进行更新
    public boolean orderDiningTable(int id,String ordername,String orderTel){
      int update= diningTableDao.update(
               "update diningtable set state = '已预订' ,ordername=? ,orderTel=? where id = ? ",ordername,orderTel,id);
      return update>0;
    }

    //提供一个更新餐桌状态的方法
    public boolean updateDiningTableState(int id,String state){
       int update= diningTableDao.update("update diningtable set state = ? where id = ? ",state,id);
       return update>0;
    }

    //将指定餐桌置为空闲状态
    public boolean updateDiningTableStateToFree(int id,String state){
        int update= diningTableDao.update("update diningtable set state = ? ,ordername='',orderTel='' where id = ? ",state,id);
        return update>0;
    }
}
